home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / EX2_7.C < prev    next >
C/C++ Source or Header  |  1992-08-20  |  2KB  |  50 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/Regexp.h>            // Include Regexp header file
  14.  
  15. CoolRegexp r1("Hi There");            // Define simple pattern
  16.  
  17. int main (void) {
  18.   char* dummy = "Garbage Hi There garbage";    // Dummy string to search
  19.   cout << "The pattern `Hi There' ";        // Output start of sentence
  20.   if (r1.find (dummy) == TRUE)                // Pattern found in string?
  21.     cout << "is";                // Yes, indicate afirmative
  22.   else
  23.     cout << "is not";                // Else indicate failure
  24.   cout << " found in `" << dummy << "'\n";    // And complete output
  25.   cout << "The pattern begins at zero-relative index " << r1.start ();
  26.   cout << " and ends at index " << r1.end () << "\n";
  27.   r1.compile("[^ab1-9]");            // Complex pattern
  28.   strcpy (dummy, "ab123QQ59ba");        // Another string to search
  29.   cout << "The pattern `[^ab1-9]' ";        // Output start of sentence
  30.   if (r1.find (dummy) == TRUE)                // Pattern found in string?
  31.     cout << "is";                // Yes, indicate afirmative
  32.   else
  33.     cout << "is not";                // Else indicate failure
  34.   cout << " found in `" << dummy << "'\n";    // And complete output
  35.   cout << "The pattern begins at zero-relative index " << r1.start ();
  36.   cout << " and ends at index " << r1.end () << "\n";
  37.   r1.compile("O(.*r)");                // New complex pattern
  38.   strcpy (dummy, "That's OK for me. OK for you?"); // Another string to search
  39.   cout << "The pattern `O(.*r)' ";        // Output start of sentence
  40.   if (r1.find (dummy) == TRUE)                // Pattern found in string?
  41.     cout << "is";                // Yes, indicate afirmative
  42.   else
  43.     cout << "is not";                // Else indicate failure
  44.   cout << " found in `" << dummy << "'\n";    // And complete output
  45.   cout << "The pattern begins at zero-relative index " << r1.start ();
  46.   cout << " and ends at index " << r1.end () << "\n";
  47.   return (0);                    // Exit with OK status
  48. }
  49.  
  50.